package comparable_1102;


import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {
    static class CustomComparator implements Comparator<String> {
        private int transfer(String s) {
            switch (s) {
                case "零": return 0;
                case "一": return 1;
                case "二": return 2;
                case "三": return 3;
                case "四": return 4;
                case "五": return 5;
                case "六": return 6;
                case "七": return 7;
                case "八": return 8;
                case "九": return 9;
                default: return -1;
            }
        }

        @Override
        public int compare(String o1, String o2) {
            // o1 和 o2 一定是 "零", "一", "二", "三", "四", "五", "六", "七", "八", "九"
            return transfer(o1) - transfer(o2);
        }
    }

    public static void main(String[] args) {
        CustomComparator c = new CustomComparator();
        Queue<String> pq = new PriorityQueue<>(c);

        pq.offer("三");
        pq.offer("九");
        pq.offer("七");
        pq.offer("五");

        System.out.println(pq.poll());  // 三
    }

    public static void main1(String[] args) {
        Queue<Integer> pq = new PriorityQueue<>();
        // 不是先进先出，而是小堆规则

        pq.offer(3);
        pq.offer(9);
        pq.offer(7);
        pq.offer(5);
        System.out.println(pq.isEmpty());
        System.out.println(pq.size());

        System.out.println(pq.peek());  // 3
        System.out.println(pq.poll());  // 3
        System.out.println(pq.poll());  // 5
        System.out.println(pq.poll());  // 7
        System.out.println(pq.poll());  // 9

        pq.clear();
    }
}
